﻿using ff14bot.Enums;
using ff14bot.Managers;
using TreeSharp;
using Magitek.Helpers;
using ff14bot;
using ff14bot.Objects;
using ff14bot.Behavior;

namespace Magitek.Rotations
{
    public class Monk : Magitek
    {
        public override float PullRange { get { return WindowSettings.MonkPullRange; } }
        public override ClassJobType[] Class { get { return new ClassJobType[] { ClassJobType.Monk }; } }

        #region Pulling & Resting
        protected override Composite CreatePull()
        {
            return Combat.CreatePull(2);
        }

        protected override Composite CreateRest()
        {
            return Extensions.DefaultRestBehavior(r => Core.Player.CurrentManaPercent);
        }
        #endregion
        #region Buffs // Mainly used for Grindbot etc...
        protected override Composite CreatePreCombatBuffs()
        {
            return new PrioritySelector(
                Extensions.SummonChocobo()
                );
        }

        protected override Composite CreateCombatBuffs()
        {
            return new PrioritySelector(

            );
        }

        #endregion
        #region Combat
        protected override Composite CreateHeal()
        {
            return new PrioritySelector(

            );
        }

        protected override Composite CreateCombat()
        {
            return new PrioritySelector(ctx => Core.Player.CurrentTarget,
                new Decorator(ctx => ctx != null,
                new PrioritySelector(
                new Decorator(ctx => ctx != null && BotManager.Current.IsAutonomous,
                    new PrioritySelector(
                        CommonBehaviors.MoveToLos(ctx => ctx as GameObject),
                        CommonBehaviors.MoveAndStop(ctx => (ctx as GameObject).Location, ctx => 3 + (ctx as GameObject).CombatReach, true, "Moving to unit")
						)
					),

                Casting.Cast(r => "Steel Peak", r => WindowSettings.InterruptCast && Combat.CheckForInterrupt(), r => Core.Player.CurrentTarget, r => 2, r => false),
                Casting.Cast(r => "Arm of the Destroyer", r => WindowSettings.InterruptCast && Combat.CheckForInterrupt(), r => Core.Player.CurrentTarget, r => 2, r => false),

                Combat.DoPVP(),
                Casting.Cast(r => "Fists of Earth", r => Core.Player.CurrentHealthPercent <= WindowSettings.MonkUseFistsOfEarthHp && !Core.Player.HasAura("Fists of Earth"), r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Mantra", r => Core.Player.CurrentHealthPercent < WindowSettings.MonkUseMantraHp, r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Second Wind", r => Core.Player.CurrentHealthPercent < WindowSettings.MonkUseSecondWindHp, r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Featherfoot", r => Core.Player.CurrentHealthPercent < WindowSettings.MonkUseFeatherfootHp, r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Invigorate", r => Core.Player.CurrentTPPercent <= WindowSettings.MonkUseInvigorateTp, r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Steel Peak", r => !WindowSettings.InterruptCast, r => Core.Player.CurrentTarget, r => 2, r => false),
                Casting.Cast(r => "Fists of Fire", r => Core.Player.CurrentHealthPercent > WindowSettings.MonkUseFistsOfEarthHp && !Core.Player.HasAura("Fists of Fire"), r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Perfect Balance", r => true, r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Snap Punch", r => Core.Player.HasAura("Perfect Balance") && !Core.Player.HasAura("Greased Lightning III"), r => Core.Player.CurrentTarget, r => 2, r => false),
                Casting.Cast(r => "Haymaker", r => true, r => Core.Player.CurrentTarget, r => 2, r => true),
                Casting.Cast(r => "Internal Release", r => Core.Player.CurrentTarget.HasAura("Dragon Kick") && Core.Player.HasAura("Twin Snakes") && Core.Player.HasAura("Greased Lightning III"), r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Blood for Blood", r => Core.Player.CurrentTarget.HasAura("Dragon Kick") && Core.Player.HasAura("Twin Snakes") && Core.Player.HasAura("Greased Lightning III"), r => Core.Player, r => 2, r => false),
                Casting.Cast(r => "Dragon Kick", r => !Core.Player.CurrentTarget.HasAura("Dragon Kick") && Core.Player.HasAura("Opo-opo Form"), r => Core.Player.CurrentTarget, r => 2, r => false),
                Casting.Cast(r => "Twin Snakes", r => Core.Player.HasAura("Raptor Form") && !Core.Player.HasAura("Twin Snakes"), r => Core.Player.CurrentTarget, r => 2, r => false),
                Casting.Cast(r => "Touch of Death", r => !Core.Player.CurrentTarget.HasAura("Touch of Death", true), r => Core.Player.CurrentTarget, r => 2, r => true),
                Casting.Cast(r => "Fracture", r => WindowSettings.MonkUseFracture && !Core.Player.CurrentTarget.HasAura("Fracture", true), r => Core.Player.CurrentTarget, r => 2, r => true),
                Casting.Cast(r => "Howling Fist", r => WindowSettings.MonkUseHowlingFistSingle, r => Core.Player.CurrentTarget, r => 2, r => false),
                new Decorator(ret =>
                {
                    if (!Core.Player.CurrentTarget.IsFlanking)
                        return false;
                    return true;
                }, new PrioritySelector(
                    Casting.Cast(r => "Rockbreaker", r => Extensions.EnemiesNearTarget(5) >= WindowSettings.MonkUseAOENumber && WindowSettings.MonkUseAOE && Core.Player.HasAura("Coeurl Form") && !WindowSettings._dontaoeList.Contains(Core.Player.CurrentTarget.Name), r => Core.Player.CurrentTarget, r => 2, r => false),
                    Casting.Cast(r => "Snap Punch", r => Core.Player.HasAura("Coeurl Form"), r => Core.Player.CurrentTarget, r => 2, r => false),
                    Casting.Cast(r => "Twin Snakes", r => Core.Player.HasAura("Raptor Form"), r => Core.Player.CurrentTarget, r => 2, r => false),
                    Casting.Cast(r => "Dragon Kick", r => true, r => Core.Player.CurrentTarget, r => 2, r => false)
                    )),
                new Decorator(ret =>
                {
                    if (!Core.Player.CurrentTarget.IsBehind)
                        return false;
                    return true;
                }, new PrioritySelector(
                    Casting.Cast(r => "Rockbreaker", r => Extensions.EnemiesNearTarget(5) >= WindowSettings.MonkUseAOENumber && WindowSettings.MonkUseAOE && Core.Player.HasAura("Coeurl Form") && !WindowSettings._dontaoeList.Contains(Core.Player.CurrentTarget.Name), r => Core.Player.CurrentTarget, r => 2, r => false),
                    Casting.Cast(r => "Demolish", r => Core.Player.HasAura("Coeurl Form"), r => Core.Player.CurrentTarget, r => 2, r => false),
                    Casting.Cast(r => "True Strike", r => Core.Player.HasAura("Raptor Form"), r => Core.Player.CurrentTarget, r => 2, r => false),
                    Casting.Cast(r => "Bootshine", r => true, r => Core.Player.CurrentTarget, r => 2, r => false)
                    )),
                Casting.Cast(r => "Shoulder Tackle", r => Core.Player.CurrentTarget.Location.Distance(Core.Player.Location) > 10 && Core.Player.CurrentTarget.Location.Distance(Core.Player.Location) < 20 && WindowSettings.MonkUseShoulderTackle, r => Core.Player.CurrentTarget, r => 2, r => false),
                Casting.Cast(r => "Bootshine", r => true, r => Core.Player.CurrentTarget, r => 2, r => true)
                )));
        }
        #endregion
    }
}